<?php
//header('Content-type: text/html; charset=UTF-8'); 
// example of how to use basic selector to retrieve HTML contents
include_once("wp-config.php");
include_once("wp-load.php");
include_once("wp-includes/wp-db.php");
include('simple_html_dom.php');
global $wpdb;
global $user_ID;
 
// get DOM from URL or file
$html = file_get_html('http://www.allocine.fr/film/agenda.html');
$code_player = "<object height='485px' width='100%'>
<param name='movie' value='http://www.allocine.fr/blogvision/19145946'></param>
<param name='allowFullScreen' value='true'></param>
<param name='allowScriptAccess' value='always'></param>
<embed src='http://www.allocine.fr/blogvision/%j%' type='application/x-shockwave-flash' width='100%' height='485px' allowFullScreen='true' allowScriptAccess='always'></embed>
</object>";

//
echo 'debut de boucle';
foreach($html->find('div.mainzone') as $article) {
    $item['title']     = $article->find('div.titlebar', 0)->plaintext;
    $item['resume']    = $article->find('div.contenzone', 0)->plaintext;
    $item['poster'] = $article->find('div.picturezone', 0)->innertext;
	$item['id_ba'] = $article->find('ul.functionsmenu a', 1)->outertext;
	$item['id_ba'] = substr($item['id_ba'], 59,8);
	$item['code_ba'] = str_replace('%j%', $item['id_ba'], $code_player);
	
	
	//$item['poster'] = substr($item['poster'], 0, -5);
	//$item['poster'] = substr($item['poster'], 92);
	//$item['poster'] = substr($item['poster'], 10, 72);
	$item['resume'] = str_replace('Ajouter et noter', '', $item['resume']);
	$item['resume'] = str_replace('Voir la bande annonce', '', $item['resume']);
	$item['resume'] = str_replace($item['title'], '', $item['resume']);
// Sortie poru debogage
	//$articles[] = $item;
	//echo $item['title'].'<br/>';
	//echo $item['resume'].'<br/>';
	$portionImg = str_get_html($item['poster']);
		foreach($portionImg->find('div.picturezone img') as $img) {
			$item['poster'] = $img->src;
		}
	echo $item['poster'].'<br/>';
	//echo $item['id_ba'].'<br/>';
	//echo $item['code_ba'].'<br/>';


	$post_content = $item['code_ba'].''.$item['resume'];
	//echo '=========================='.$post_content;
			$new_post = array(
				'post_title' => $item['title'],
				'post_content' => $post_content,
				'post_status' => 'publish',
				'post_date' => date('Y-m-d H:i:s'),
				'post_author' => $user_ID,
				'post_type' => 'post',
				'post_category' => array(0),
				'filter' => true
			);
		
		
		$post_id = wp_insert_post($new_post);
		$post_meta = add_post_meta($post_id, 'poster', $item['poster']); 
		}
	




?>